'use strict';
const { Service } = require('egg');
const ModelName = 'Banner'
class RouterService extends Service {
  async getPage(where, page, pageSize) {
    return this.ctx.model[ModelName].findAndCountAll({
      where,
      offset: pageSize * (page - 1),
      limit: pageSize,
      order:[
        // id 降序
        ['created_at','DESC']
      ],
    });
  }
  // 所有列表
  async allList() {
    return this.ctx.model[ModelName].findAll({
      where: {
        status: 1,
      },
      order:[
        // id 降序
        ['created_at','DESC']
      ],
    });
  }
  async findOne(id) {
    return this.ctx.model[ModelName].findOne({
      where: {
        id,
      },
    });
  }
  async create(data) {
    return this.ctx.model[ModelName].create(data);
  }
  async update(id, data) {
    return await this.ctx.model[ModelName].update(data, { where: { id } });
  }
  async deleteById(id) {
    return await this.ctx.model[ModelName].update({
        delete_flag: 1
    }, { where: { id } });
  }
}

module.exports = RouterService;
